package com.atguigu.serviceedu.controller;

import com.atguigu.exception.Guliexception;
import com.atguigu.serviceedu.entity.vo.EduSubjectVO;
import com.atguigu.serviceedu.service.EduSubjectService;
import com.atguigu.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;

@RestController
@RequestMapping("/serviceedu/subject")
@CrossOrigin
public class EduSubjectController {
    @Autowired
    private EduSubjectService eduSubjectService;
    @PostMapping("/batchImportSubject")
    public ResultVO batchImportSubject(@RequestParam("file") MultipartFile file){
        InputStream inputStream=null;
        try {
            inputStream = file.getInputStream();
            eduSubjectService.batchimportsubjects(inputStream);
            return ResultVO.ok().Msg("Excel批量导入课程分类成功!");
        }catch (Exception e) {
            e.printStackTrace();
            throw new Guliexception(20001,"Excel批量导入课程分类失败!");
        }
    }
    @GetMapping("/getNestedListByParentId/{id}")
    public ResultVO getNestedListByParentId(@PathVariable("id") String parentId){
        List<EduSubjectVO> eduSubjectVOS = eduSubjectService.queryNestedListByParentId(parentId);
        return ResultVO.ok().Msg("获取分类列表成功").Data("items",eduSubjectVOS);
    }
}
